package org.smr.ministore.micro;

import java.util.List;

import org.smr.ministore.dao.EmployeeMapper;
import org.smr.ministore.entities.Employee;
import org.smr.ministore.service.EmployeeService;

import org.blade.utils.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class EmployeeMicroService implements EmployeeService {

	@Autowired
	private EmployeeMapper mapper;

	@ResponseBody
	@RequestMapping(method = RequestMethod.POST, value = "/Employee/batchSave")
	public int batchSave(@RequestBody List<Employee> entities) {
    	return mapper.batchInsert(entities);
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.PUT, value = "/Employee/save")
    public int save(@RequestBody Employee entity) {
    	return mapper.insert(entity);
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.PATCH, value = "/Employee/updateById")
    public int updateById(@RequestBody Employee id) {
   	 	return mapper.updateById(id);
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/Employee/queryById/{id}")
    public Employee queryById( @PathVariable("id")Long id ) {
    	return (Employee) mapper.selectById(id);
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.DELETE, value = "/Employee/deleteById/{id}")
    public int deleteById( @PathVariable("id")Long id ) {
        return mapper.deleteById(id);
    }

    @ResponseBody
    @RequestMapping( method = RequestMethod.POST, value = "/Employee/paginate/{pageSize}/{pageNum}")
    public Pager<Employee> paginate( Employee entity, @PathVariable("pageSize")Long pageSize,  @PathVariable("pageNum")Long pageNum ) {
        Pager<Employee> pager = new Pager(pageSize, pageNum);
        List<Employee> list = this.mapper.pagination( entity, pager );
        pager.setEntities(list);
        return pager;
    }


}
